package com.spsoft.workflow.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.workflow.entity.WfProcessTemplates;
import com.spsoft.workflow.model.dto.template.WfProcessTemplateSaveDto;
import com.spsoft.workflow.model.dto.template.WfProcessTemplatesQueryDto;
import com.spsoft.workflow.model.vo.biz.WfProcessTemplatesVo;
import com.spsoft.workflow.service.WfProcessTemplatesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 流程审批摸板;--主键序列 SEQ_WF_PROCESS_TEMPLATES 前端控制器
 * </p>
 *
 * @author dlchen
 * @since 2023-11-13
 */
@Api(tags = {"流程模版管理"})
@RestController
@RequestMapping("/wfProcessTemplates")
@RequiredArgsConstructor
@Validated
@Slf4j
public class WfProcessTemplatesController extends BaseController {
    private final WfProcessTemplatesService processTemplatesService;

    @ApiOperation("查询审批流程模板列表")
    @AnonymousAccess(value = "/list", method = RequestMethod.POST ,permissionCode = "VMS_WORKFLOW")
    @Log(value = "查询审批流程模板列表", type = LogActionType.SELECT, menuName = LogMenuEnum.WORKFLOW)
    public Result<IPage<WfProcessTemplatesVo>> queryPageList(@RequestBody @Valid WfProcessTemplatesQueryDto templateDto) {
        return processTemplatesService.queryPageList(templateDto);
    }


    @ApiOperation("查询单个审批流程模板数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "模板id", dataTypeClass=Integer.class,dataType = "Integer", paramType = "query", required = true),
    })
    @AnonymousAccess(value = "/getFormTemplateById", method = RequestMethod.GET,permissionCode = "VMS_WORKFLOW")
    @Log(value = "查询单个审批流程模板数据", type = LogActionType.SELECT, menuName = LogMenuEnum.WORKFLOW)
    public Result<WfProcessTemplates> getFormTemplateById(Long id) {
        return processTemplatesService.getFormTemplateById(id);
    }

    @ApiOperation("保存单个审批流程模板数据")
    @AnonymousAccess(value = "/saveTemplate", method = RequestMethod.POST,permissionCode = "VMS_WORKFLOW")
    @Log(value = "保存单个审批流程模板数据", type = LogActionType.ADD,  menuName = LogMenuEnum.WORKFLOW)
    public Result saveTemplate(@RequestBody @Valid WfProcessTemplateSaveDto templateDto) {
        return processTemplatesService.saveTemplate(templateDto);
    }


    @ApiOperation("修改单个审批流程模板数据")
    @AnonymousAccess(value = "/updateTemplate", method = RequestMethod.POST,permissionCode = "VMS_WORKFLOW")
    @Log(value = "修改单个审批流程模板数据", type = LogActionType.UPDATE, menuName = LogMenuEnum.WORKFLOW)
    public Result updateTemplate(@RequestBody WfProcessTemplateSaveDto templateDto) {
        return processTemplatesService.updateTemplate(templateDto);
    }


    @ApiOperation("查看流程图xml")
    @AnonymousAccess(value = "/getBMPNXml", method = RequestMethod.POST ,permissionCode = "VMS_WORKFLOW")
    @Log(value = "查看流程图xml", type = LogActionType.SELECT, menuName = LogMenuEnum.WORKFLOW)
    public Result getBMPNXml(@RequestBody WfProcessTemplateSaveDto templateDto) {
        return processTemplatesService.getBMPNXml(templateDto);
    }
}

